package com.bicon.botu.mall.order.api;

import com.bicon.botu.core.base.common.controller.BaseController;
import com.bicon.botu.core.base.common.entity.BaseResult;
import com.bicon.botu.mall.order.common.OrderConstans;
import com.bicon.botu.mall.order.entity.Invoice;
import com.bicon.botu.mall.order.entity.MyInvoice;
import com.bicon.botu.mall.order.service.IInvoiceService;
import com.bicon.botu.mall.order.service.IMyInvoiceService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 个人发票 客户端控制器
 * @author 李双喜
 * @since 2018-06-07
 */
@RestController
@RequestMapping("/V3.0.0/api/invoice")
public class InvoiceControllerApiV3 extends BaseController {

    @Autowired
    private IInvoiceService iInvoiceService;

    /**
     * 保存个人发票信息
     * @param invoice
     * @return
     */
    @RequestMapping(value="saveOrUpdate",method = RequestMethod.POST)
    public BaseResult svaeOrUpdate(Invoice invoice){
        //必要参数校验
        if(invoice != null && StringUtils.isNotBlank(invoice.getUserId())
                && invoice.getType() != null){
            //保存或修改调用Service处理方法
            Invoice result=iInvoiceService.saveOrUpdate(invoice);
            if(result != null){
                return sendResult200(result.getId());
            }else {
                return sendResult(OrderConstans.RESPONSE_CODE_600,OrderConstans.RESPONSE_MESSAGE_600);
            }
        }else {
            return sendResult400();
        }
    }
}
